<template>
  <section class="table deptLeaveTable">
   <h2 class="title">本部门近期休假情况</h2>
     
    
    <section style='overflow:hidden'>
     
      <div style='float:left'>
        <div style='height:70px' >
        </div>
        <div class='name' v-for='k in tableData'>
          {{k.name}}
        </div>
      </div>
      <div class="right">
        <ul class="month" :class='{nodata:!tableData.length}'>
          <li>{{twoDate.start}}</li>
          
          <li>{{twoDate.end}}</li>
        </ul>
        <el-table
          border
          :data='tableData'
          class='table-el'
          ref='vacationTable'
          :class='{"table-el-nodata":!tableData.length}'
        >

          <el-table-column
            v-for='(k,i) in tableLabel'
            :key='i'
            min-width="60"
            align='center'
            :label-class-name='handleTitleClass(k)'
            v-tableTitle:data='k'

          >
            <template scope="scope">
              <span class="table-icon" :class='handleIconColor(i,scope.row)'>{{ handleColumn(i,scope.row)}}</span>
            </template>
          </el-table-column>


        </el-table>
      </div>  
    </section>
  </section>
</template>

<script>
import Vue from 'vue'
import { Table, TableColumn, Tag } from 'element-ui'
Vue.use(Tag)
Vue.use(Table)
Vue.use(TableColumn)
export default {
	data () {
		return {
			tableData: [],
			tableLabel: []
		}
	},
	computed: {
		twoDate () {
			if (this.tableLabel.length) {
				let start,
					end,
					len = this.tableLabel.length;
				(start = this.tableLabel[0].value),
				(end = this.tableLabel[len - 1].value)

				return {
					start:
            start
            	.split('-')
            	.splice(0, 2)
            	.join('年') + '月',
					end:
            end
            	.split('-')
            	.splice(0, 2)
            	.join('年') + '月'
				}
			}

			return { end: '-', start: '-' }
		}
	},
	mounted () {
		// this.getTableData()
	},
	methods: {
		getTableData () {
			this.Axios.Post(this.URL.tabQueryList.url).then(res => {
				const changeTableTitle = () => {
					return new Promise((reslove) => {
						const data = res.data.datas
						this.tableData = data.showList
						this.tableLabel = data.dateList
						reslove()
					})
				}

				changeTableTitle().then(() => {
					let list = document.querySelector('thead').querySelectorAll('div')
					// let list2 = document.querySelector('thead').querySelectorAll('tr');

					// list2.style.position = 'relative'
					// let i = document.created('i')

					// i.style.position = 'abosolute'

					//  i.style.left = 0

					//  i.style.top = 0

					//  i.style.width = '10px'
					//  i.style.width = '1px'

					for (let i = 0; i < list.length; i++) {
						list[i].innerHTML = `${this.tableLabel[i].value
							.replace(/[^0-9]/gi, '')
							.slice(-2, 10)}<br />${this.tableLabel[i].week}`
					}
				})
			})
		},
		handleTitleLabel (k, e) {
			const str = k.value.replace(/[^0-9]/gi, '').slice(-2, 10)
			var test = `${str} / ${k.week} `
			return test
		},

		handleTitleClass (k) {
			if (k.status == 0) {
				return 'color pass'
			} else if (k.week == '六' || k.week == '日') {
				return 'color weeken'
			} else {
				return 'color'
			}
		},
		handleIconColor (i, row) {
			let status = this.tableLabel[i].status,
				type

			for (const key in row) {
				if (key.startsWith('day')) {
					if (key.replace(/[^0-9]/gi, '') == i) {
						if (row[key]) {
							type = row[key]
						}
					}
				}
			}

			if (status == 0) {
				return 'gray'
			} else if (type == '上午') {
				return 'green'
			} else if (type == '下午') {
				return 'purple'
			} else {
				return 'blue'
			}
		},
		handleColumn (index, row) {
			for (const key in row) {
				if (key.startsWith('day')) {
					if (key.replace(/[^0-9]/gi, '') == index) {
						if (row[key]) {
							return row[key]
						}
					}
				}
			}
		}
	},
	directives: {
		tableTitle: {}
	}
}
</script>

<style  lang='less'>
.table.deptLeaveTable {
  margin-top: 1%;

  border-bottom: 8px solid #ecf0f5;

  padding: 25px 15px 40px 15px;
  background-color: #fff;
  // margin-bottom: 8px;
  overflow: hidden;
  .el-table span,
  .el-table td,
  .el-table th,
  .el-table div,
  .el-table tr {
    padding: 0 !important;
    margin: 0 !important;
  }
  .color {
    background-color: #fff;
    font-weight: normal;
  }

  .weeken {
    color: #268fe5;
  }
  .pass {
    color: #cdccca;
  }

  .purple {
    background-color: #8b5ee4;
  }
  .green {
    background-color: #75d155;
  }
  .blue {
    background-color: #268fe5;
  }
  .gray {
    background-color: #cdccca;
  }

  .name {
    line-height: 40px;
    margin: 0 20px 0 50px;
    font-style: italic;
    font-size: 16px;
  }
  .table-el {
    width: 85%;
    float: left;
    background-color: #fff;
    th > .cell {
      line-height: 20px;
      text-align: center;
      // border-bottom: 1px solid #dfe6ec;
    }
  }
  .table-el-nodata {
    float: none;
    margin: 0 auto;
  }
  .table-icon {
    color: #fff;
    border-radius: 50%;
    width: 32px;
    text-align: center;
    line-height: 32px;
    display: inline-block;
  }
  .title {
    text-align: center;
    font-size: 15px;
  }

  section {
    margin-top: 10px;
    .month {
      width: 85%;
      overflow: hidden;
      li {
        margin-bottom: 10px;
        color: #268fe5;
        font-size: 15px;
        letter-spacing: 0.5px;
      }
      li:first-of-type {
        float: left;
      }
      li:last-of-type {
        float: right;
      }
    }
    .month.nodata {
      margin: 0 auto;
    }
  }
}
</style>

<style>
.table.deptLeaveTable .el-table th {
  min-height: 40px;
}
.table.deptLeaveTable div.el-table__body,
.table.deptLeaveTable div.el-table__empty-block {
  width: 100% !important;
}
</style>
